//
//  SuperWebController.m
//  MyCloudMusic
//
//  Created by xiaolong on 2023/12/31.
//

#import "SuperWebController.h"

@interface SuperWebController ()

@end

@implementation SuperWebController

- (void)initViews{
    [super initViews];
    [self initRelativeLayoutSafeArea];
    
    [self addRightImageButton:R.image.close];
    
    self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:[SuperWebController defaultConfiguration]];
    
    self.webView.myWidth = MyLayoutSize.fill;
    self.webView.myHeight = MyLayoutSize.fill;
    [self.container addSubview:self.webView];
    
   
    //[self addri]
}

- (void)initDatum{
    [super initDatum];
    
    if([StringUtil isNotBlank:self.myTitle]){
        self.toolbarView.titleView.text = self.myTitle;
    }
    
    if([StringUtil isNotBlank:self.url]){
        NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
        [self.webView loadRequest:req];
    }
}


- (void)onRightClick:(QMUIButton *)send{
    [self finish];
}

- (void)onLeftClick:(QMUIButton *)send{
    if([self.webView canGoBack]){
        [self.webView goBack];
    }
    else{
        [self finish];
    }
}

+ (void)start:(UINavigationController *)controller title:(NSString *)title uri:(nullable NSString *)uri{
    [self start:controller title:@"哈哈你的" url:@"https://www.taobao.com" content:nil];
}

+ (void)start:(UINavigationController *)controller title:(NSString *)title content:(NSString *)content{
    
}

+ (void)start:(UINavigationController *)controller title:(nullable NSString *)title url:(NSString *)url content:(NSString *)content{
    
    SuperWebController *web = [SuperWebController new];
    
    web.myTitle = title;
    web.url = url;
    web.content = content;
    [controller pushViewController:web animated:YES];
}

+ (WKWebViewConfiguration *)defaultConfiguration{
    WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
    
    if([configuration respondsToSelector:@selector(setAllowsInlineMediaPlayback:)]){
        [configuration setAllowsInlineMediaPlayback:YES];
    }
    else{
        
    }
   
    
    return configuration;
}

@end
